
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ include file="/include/head.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/servicePro/jquery.uploadify.min.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/servicePro/uploadify.css">
<script type="text/javascript">
      $(function(){  
         /**加载修改密码**/
          $("#editPwd_div_dialog").dialog({
		    autoOpen : false,
		    width : 400,
		    draggable : true,
		    resizable : false,
		    buttons : [ {
		      text : "提交",
		      click : function() {
		        updatePwd();
		        $(this).dialog("close");
		      }
		    }, {
		      text : "取消",
		      click : function() {
		        $(this).dialog("close");
		      }
		    } ]
		  });
		   /**加载修改管理员框**/
		  $("#update_manager_dialog").dialog({
		    autoOpen : false,
		    width : 700,
		    draggable : true,
		    resizable : false,
		    height:450,
		    buttons : [ {
		      text : "提交",
		      click : function() {
		      	  updateManager();
		     	 $(this).dialog("close");		      	
		      }
		    }, {
		      text : "取消",
		      click : function() {
		        $(this).dialog("close");
		        
		      }
		    } ]
	  });
	   /**加载添加管理员框**/
		  $("#add_manager_dialog").dialog({
		    autoOpen : false,
		    width : 700,
		    draggable : true,
		    resizable : false,
		    height:500,
		    buttons : [ {
		      text : "提交",
		      click : function() {
		      	  addManager();
		     	 $(this).dialog("close");		      	
		      }
		    }, {
		      text : "取消",
		      click : function() {
		        $(this).dialog("close");
		        
		      }
		    } ]
	  });
		  $("#add_manager").click(function(e) {
	        closeOtherJDialog();
	        e.stopPropagation();
	        $("#add_manager_dialog").dialog('open');
	     });
	     
	      /**添加头像上传图片**/
     $("#file_upload").uploadify({
        		    'buttonText' : '请选择活动图片',
        		    'height' : 30,
        	        'swf' : '<%=request.getContextPath()%>/resources/servicePro/uploadify.swf',
        	        'uploader' : '<%=request.getContextPath()%>/back/actBack/uploadlogo.do',
        	        'width' : 120,
        	        'multi'           : false,
                    "auto"            : false,
                    "dnd"             : true,
        	        "fileTypeExts"    : "*.png;*.jpg;*.bmp;*.gif",
                    "fileSizeLimit"   : "2MB",
        	        'fileObjName'   : 'file',
        	        'onUploadSuccess' : function(file, data, response) {
        	        	      data = eval("(" + data + ")");      	        
        	                 alert( file.name + ' 上传成功！ ');
                           $("#iphoto").val(data.picurl);
                            $("#iifUpPic").val("1");
        	            $("#uploadButton").hide();
        	            
        	        },
         'onFallback' : function() {
           alert('Flash was not detected.');
        },
         "onSelect" : function(file) {
          if ($("#file_upload-queue").children().length == 1) {
            $("#uploadButton").show();
            $("#onlyOneImg").hide();
          } else {
          
            $("#uploadButton").hide();
            $("#onlyOneImg").show();
          }
        },
           "onCancel" : function() {
          if ($("#file_upload-queue").children().length == 2) {
            $("#uploadButton").show();
            $("#onlyOneImg").hide();
          } else if ($("#file_upload-queue").children().length == 1) {
            $("#uploadButton").hide();
          } else {
            $("#uploadButton").hide();
            $("#onlyOneImg").show();
          }
        },
 		        });
 		        
      /**修改头像上传图片**/
     $("#ufile_upload").uploadify({
        		    'buttonText' : '请选择活动图片',
        		    'height' : 30,
        	        'swf' : '<%=request.getContextPath()%>/resources/servicePro/uploadify.swf',
        	        'uploader' : '<%=request.getContextPath()%>/back/actBack/uploadlogo.do',
        	        'width' : 120,
        	        'multi'           : false,
                    "auto"            : false,
                    "dnd"             : true,
        	        "fileTypeExts"    : "*.png;*.jpg;*.bmp;*.gif",
                    "fileSizeLimit"   : "2MB",
        	        'fileObjName'   : 'file',
        	        'onUploadSuccess' : function(file, data, response) {
        	        	      data = eval("(" + data + ")");      	        
        	                 alert( file.name + ' 上传成功！ ');
                           $("#uphoto").val(data.picurl);
                            $("#uifUpPic").val("1");
        	            $("#uuploadButton").hide();
        	            
        	        },
         'onFallback' : function() {
           alert('Flash was not detected.');
        },
         "onSelect" : function(file) {
            $("#uuploadButton").show();
        },
           "onCancel" : function() {
            $("#uuploadButton").hide();
            $("#uonlyOneImg").show();
        },
 		        });
      }); 
      
      /**修改密码**/
     function updatePwd(){
	    var userid=$.trim($("#userid").val());
	    var newpwd=$.trim($("#newpwd").val());  
	    var newPwdQue=$.trim($("#newPwdQue").val());  
	    if(newpwd.length==0  || newPwdQue.length==0){
	      alert("输入信息不能为空!");
	        return false;
	    } 
	     if(newpwd!=newPwdQue){
	      alert("密码不一致!");
	        return false;
	    } 
	          $.ajax( {
				type : "POST",
				url : "<%=request.getContextPath()%>/back/manager/optManager.do",
				data:{"optype":2,"user_id":userid,"account_password":newpwd,"updatetype":2},
				dataType: "json",
				async : false,
				success : function(data) {
					if(data.code=="0000"){
			       		 alert("操作成功!");
			       		 location.reload();
			       }else{
			           alert(data.code+data.codeMsg);
			       }
				}
		  });            
     }
    /**修改管理员信息**/
     function updateManager(){
	    var uid=$.trim($("#uid").val());
	    var uphone=$.trim($("#uphone").val());  
	    var uname=$.trim($("#uname").val());
	    var ustatus=$.trim($("#ustatus").val()); 
	    var telReg = !!uphone.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
	    var iphoto=$.trim($("#uphoto").val()); 
	    var uploypic=$.trim($("#uploypic").val());  
	    var iifUpPic=$.trim($("#uifUpPic").val()); 
	    var inick=$.trim($("#unick").val()); 
	    if(telReg == false){
	     alert("手机号格式不正确!");
	        return false;
	    } 
	    if(uphone.length==0  || uname.length==0||iphoto.length==0  || iifUpPic.length==0|| inick.length==0){
	      alert("输入信息不能为空!");
	        return false;
	    } 
	          $.ajax( {
				type : "POST",
				url : "<%=request.getContextPath()%>/back/manager/optManager.do",
				data:{"optype":2,"user_id":uid,"phone":uphone,"user_name":uname,"is_eff":ustatus,"updatetype":1,"photo":iphoto,"ifUpPic":iifUpPic,"nick_name":inick},
				dataType: "json",
				async : false,
				success : function(data) {
					if(data.code=="0000"){
			       		 alert("操作成功!");
			       		 location.reload();
			       }else{
			           alert(data.code+data.codeMsg);
			       }
				}
		  });            
     }
      /**添加管理员信息**/
     function addManager(){
	    var iphone=$.trim($("#iphone").val());  
	    var iname=$.trim($("#iname").val());
	    var ipwd=$.trim($("#ipwd").val());  
	    var inewpwd=$.trim($("#inewpwd").val());
	    var irole=$.trim($("#irole").val());
	    var ischool=$.trim($("#ischool").val()); 
	    var iphoto=$.trim($("#iphoto").val());  
	    var iifUpPic=$.trim($("#iifUpPic").val()); 
	    var inick=$.trim($("#inick").val()); 
	    if(iphone.length==0  || iname.length==0||ipwd.length==0  || inewpwd.length==0||iphoto.length==0  || iifUpPic.length==0|| inick.length==0){
	      alert("输入信息不能为空!");
	        return false;
	    } 
	    var telReg = !!iphone.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
	    if(telReg == false){
	     alert("手机号格式不正确!");
	        return false;
	    }
	     if(ipwd!=inewpwd){
	      alert("密码不一致!");
	        return false;
	    } 
	          $.ajax( {
				type : "POST",
				url : "<%=request.getContextPath()%>/back/manager/optManager.do",
				data:{"optype":1,"account_password":ipwd,"phone":iphone,"user_name":iname,"user_type":irole,"schoolid":ischool,"photo":iphoto,"ifUpPic":iifUpPic,"nick_name":inick},
				dataType: "json",
				async : false,
				success : function(data) {
					if(data.code=="0000"){
			       		 alert("操作成功!");
			       		 location.reload();
			       }else{
			           alert(data.code+data.codeMsg);
			       }
				}
		  });            
     }
     function loadSchool(){
     var irole=$.trim($("#irole").val()); 
       if(irole==4){
       $("#schooltrid").show();
        $.ajax({          
	             url:"<%=request.getContextPath()%>/back/manager/getScool.do", 
	             type : "post",    
	             cache : false,    
	             dataType : "json",   
	             error:function(){  
	             },  
	             success:function(data){
	                var categoryId = document.getElementById('ischool');  
	                //清空数组  
	                categoryId.length = 0;  
	                for(var i=0;i<data.length;i++){  
	                     var xValue=data[i].schoolId;    
	                     var xText=data[i].schoolName;    
	                     var option=new Option(xText,xValue);    
	                     categoryId.add(option);    
	                }  
	               
	           }  
	       });  
       }else{
          $("#schooltrid").hide();
       }
     
     }
   </script>
<title>Document</title>


</head>
<body  >
	<div class="container">
		<div class="main_top">

			<div class="main_right fr span10">

				<div class="box pl5">
					<div class="box_border">
						<div class="box_top">
							<div class="box_top_l fl">
								<b class="pl15">数据</b>
							</div>
						</div>
						<div class="box_center">
					<form id="form1" method="post" action="<%=request.getContextPath()%>/back/manager/getManagerList.do">
								<div class="searchDiv fl">
						
									<b>请输入姓名或手机号进行搜索</b>
									 <input type="text" name="findkey" class="input-text lh30" style="width:300px" maxlength="50" value="${findkey }">  
									 <input type="submit" value="搜索" class="btn btn82 btn_search">

								</div>
						
							</form>
					
								<div class="searchDiv fr">
								<input type="button"  id="add_manager"  class="new_btn new_btn_publish new_btn_big" 
											value="添加管理员">
									    
								</div>
							</form>
							<div id="table" class=" fl mt10">
								<div class="box span10 oh">
									<table width="100%" border="0" cellpadding="0" cellspacing="0"
										class="list_table">
										<tr>
											<th width="1.5%">序号</th>
											<th width="3%">账户</th>
											<th width="5%">姓名</th>
											<th width="5%">昵称</th>
											<th width="5%">手机</th>
											<th width="5%">状态</th>
											<th width="5%">管理员所属</th>
											<th width="5%">创建时间</th>
											<th width="5%">操作</th>
										</tr>
										<c:if test="${fn:length(managerList)==0}"><tr class="tr"><td align="center" colspan="7">暂无数据</td> </tr></c:if>
										<c:if test="${fn:length(managerList)>0}">
										<c:forEach items="${managerList}" var="manager" varStatus="abc">
											<tr class="tr">
											    <td align="center"><c:out value="${(PageBean.currentpage-1)*PageBean.pagesize+abc.index + 1}" /></td>
												<td align="center"><c:out value="${manager.account_number}" /></td>
												<td align="center"><c:out value="${manager.user_name}" /></td>
												<td align="center"><c:out value="${manager.nick_name}" /></td>
												<td align="center"><c:out value="${manager.phone}" /></td>
												<td align="center">
												  <c:if test="${manager.is_eff == '0' }">无效</c:if>
												  <c:if test="${manager.is_eff == '1' }">有效</c:if>
												</td>
											         <td align="center">
												  <c:if test="${manager.user_type == '4' }">${manager.schoolName }</c:if>
												  <c:if test="${manager.user_type == '5' }">官方</c:if>
												</td>
												<td align="center"><c:out value="${manager.create_time}" /></td>
												<td align="center">
												  <input type="button" class="new_btn new_btn_change" value="修改密码"  >
												  <input type="button" class="new_btn new_btn_up" value="更新"  >
												  </td>
												  <td style="display:none;"><c:out value="${manager.user_id}" /></td>
												  <td style="display:none;"><c:out value="${manager.is_eff}" /></td>
												  <td style="display:none;"><c:out value="${manager.nick_name}" /></td>
												  <td style="display:none;"><c:out value="${manager.photo}" /></td>
											</tr>
										</c:forEach>
                                     </c:if>
									</table>
									<div class="fr fontblack mt25 mb20 mr20">
										每页条数：<a href="<%=request.getContextPath()%>/back/manager/getManagerList.do?pz=5"
											class="${pageSize == 5 ? 'fontpink' : ''}">5</a> | <a
											href="<%=request.getContextPath()%>/back/manager/getManagerList.do?pz=10"
											class="${pageSize == 10 ? 'fontpink' : ''}">10</a> | <a
											href="<%=request.getContextPath()%>/back/manager/getManagerList.do?pz=20"
											class="${pageSize == 20 ? 'fontpink' : ''}">20</a>
									</div>
									<div class="fr fontblack mt5 mb20 mr20">
										<jsp:include page="../template/commonPagination.jsp">
											<jsp:param name="url" value="getManagerList.do?"></jsp:param>
										</jsp:include>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="clear"></div>
		</div>

	</div>
	
 <script type="text/javascript">
	     $("#table tr").on("click", "td:eq(8) input:eq(0)", function(e) {
	        closeOtherJDialog();
	        e.stopPropagation();
	        var dialog =  $("#editPwd_div_dialog");
	         dialog.dialog("open");
              var tr = $(this).parent().parent();
		      tr.data("tdArr", ["td:eq(9)"]);
		      tr.data("inputArr", ["input:eq(0)"]);
		      for (var i = 0, length = tr.data("tdArr").length; i < length; i++) {
		       $(tr.data("inputArr")[i], dialog).val($.trim($(tr.data("tdArr")[i], tr).text()));
		 }
   
	     });
	     
	     $("#table tr").on("click", "td:eq(8) input:eq(1)", function(e) {
	        closeOtherJDialog();
	        e.stopPropagation();
	        var dialog =  $("#update_manager_dialog");
	         dialog.dialog("open");
              var tr = $(this).parent().parent();
		      tr.data("tdArr", ["td:eq(9)","td:eq(4)","td:eq(2)","td:eq(10)","td:eq(11)","td:eq(12)"]);
		      tr.data("inputArr", ["input:eq(0)","input:eq(1)","input:eq(2)","select:eq(0)","input:eq(3)","input:eq(4)"]);
		      for (var i = 0, length = tr.data("tdArr").length; i < length; i++) {
		       $(tr.data("inputArr")[i], dialog).val($.trim($(tr.data("tdArr")[i], tr).text()));
		 }
   
	     });
	          
  </script> 
     <!-- 密码修改框 -->
		<div id="editPwd_div_dialog" title="修改密码" style="display:none;">
		<div class="dv_tb_news_add">
			<table class="tb_news_add" cellspacing="10">
				<tr>
					<td class="elem_td">新密码:</td>
					<td>
					<input type="hidden" name="userid" id="userid"/>
					<input  type="password" class="jbxx_form grayBack" style="width:200px;" id="newpwd"  name="newPwd"  />
					</td>
				</tr>
				<tr>
					<td class="elem_td">确认新密码:</td>
					<td><input  type="password" class="jbxx_form grayBack" style="width:200px;" id="newPwdQue"  name="newPwdQue"/>
					</td>
				</tr>
			
			</table>
			<div style="color: red " id="MesTip"></div>
		</div>
		</div>
		<!-- 更新管理员信息 -->
		<div id="update_manager_dialog" title="更新管理员信息" style="display:none;">
		<div class="box span10 oh">
			<table class="list_table"  id="tb_version_update" >
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;手机号:</td>
					<td>
					<input type="hidden" id="uid" name="uid"
										class="input-text_popup_form" style="width:300px" maxlength="50"
										>
					<input type="text" id="uphone" name="uphone" readonly="readonly"
										class="input-text_popup_form" style="width:300px" maxlength="50"
										>
										
										</td>
				</tr>
	            <tr class="tr">
					<td align="left">&nbsp;&nbsp;姓名:</td>
					<td><input type="text" id="uname" name="uname"
										class="input-text_popup_form" style="width:300px" maxlength="150"
										></td>
				</tr>
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;昵称:</td>
					<td><input type="text" id="unick" name="unick"
										class="input-text_popup_form" style="width:300px" maxlength="150"
										></td>
				</tr>
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;活动图片:</td>
					<td>
					<div>
					<input type="hidden" id="uphoto"   />
					<input type="hidden" id="uploypic"   />
							<input type="file" name="fileName" class="ml10" style="height:36px;" id="ufile_upload" /> 
							<input id="uuploadButton" type="button"
								onclick="$('#ufile_upload').uploadify('upload');" value="开始上传"
								class="ext_btn ext_btn_success" style="display:none;">
							<p class="fontpink" id="uonlyOneImg" style="display:none;">只能上传一张图片</p>
							<input type="hidden" id="uifUpPic"   value="0" />
							</div>
                    </td>
				</tr>
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;状态:</td>
					<td><select id="ustatus" name="ustatus" class="select pd10">
					<option value="0">无效</option>
					<option value="1">有效</option>
					</select>
				</td>
				</tr>
			</table>
		</div>
		</div>
		<!-- 添加管理员信息 -->
		<div id="add_manager_dialog" title="添加管理员信息" style="display:none;">
		<div class="box span10 oh">
			<table class="list_table"  id="tb_version_update" >
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;手机号:</td>
					<td>
					<input type="text" id="iphone" name="iphone"
										class="input-text_popup_form" style="width:300px" maxlength="50"
										>
										
										</td>
				</tr>
	            <tr class="tr">
					<td align="left">&nbsp;&nbsp;姓名:</td>
					<td><input type="text" id="iname" name="iname"
										class="input-text_popup_form" style="width:300px" maxlength="150"
										></td>
				</tr>
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;昵称:</td>
					<td><input type="text" id="inick" name="inick"
										class="input-text_popup_form" style="width:300px" maxlength="150"
										></td>
				</tr>
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;头像:</td>
					<td>
					<div>
							<input type="file" name="fileName" class="ml10" style="height:36px;" id="file_upload" /> 
							<input id="uploadButton" type="button"
								onclick="$('#file_upload').uploadify('upload');" value="开始上传"
								class="ext_btn ext_btn_success" style="display:none;">
							<p class="fontpink" id="onlyOneImg" style="display:none;">只能上传一张图片</p>
							<input type="hidden" id="iphoto"   />
							<input type="hidden" id="iifUpPic"   value="0" />
							</div>
                    </td>
				</tr>
				<c:if test="${sessionScope.user.role=='5' }">
				  	<tr class="tr">
					<td align="left">&nbsp;&nbsp;管理员列表:</td>
					<td><select id="irole" name="irole" class="select pd10" onchange="loadSchool();">
					<option value="5">平台管理员</option>
					<option value="4">校管理员</option>
					</select>
				</td>
				</tr>
				</c:if>
			    	<tr class="tr" style="display: none;" id="schooltrid">
					<td align="left">&nbsp;&nbsp;学校名称:</td>
					<td><select id="ischool" name="ischool" class="select pd10" >
				 
					</select>
				</td>
				</tr>   
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;密码:</td>
					<td><input type="password" id="ipwd" name="ipwd"
										class="input-text_popup_form" style="width:300px" maxlength="150"
										></td>
				</tr>
				<tr class="tr">
					<td align="left">&nbsp;&nbsp;重复输入密码:</td>
					<td><input type="password" id="inewpwd" name="inewpwd"
										class="input-text_popup_form" style="width:300px" maxlength="150"
										></td>
				</tr>
				 
			</table>
		</div>
		</div>
		
		
</body>

</html>
